﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace demo5._1_luckyDog
{
    public partial class LuckyDog : Form
    {
        ArrayList al = null;

        public LuckyDog()
        {
            InitializeComponent();
        }

        private void btn_create_Click(object sender, EventArgs e)
        {
            al = new ArrayList();
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            al.Add("张三");
            al.Add("李四");
            al.Add("王五");
            al.Add("赵六");
            al.Add("关羽");
            al.Add("刘备");
            al.Add("曹操");
            al.Add("项羽");
        }

        private void btn_show_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            foreach (object obj in al)
            {
                listBox1.Items.Add(obj);
            }
        }


        bool flag = false;
        private void btn_lucky_Click(object sender, EventArgs e)
        {
            flag = !flag;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (flag)
            {
                Random ra = new Random();
                int i = ra.Next() % al.Count;
                Console.Write(i);
                text_show.Text = al[i].ToString();
                // System.Threading.Thread.Sleep(1000);
            }
        }


    }
}
